import urllib.request

# 访问的网址
ulr = "http://www.baidu.com"

# 进行请求
response = urllib.request.urlopen(ulr)
# 状态码
print(response.getcode())
# 响应头
print(response.getheaders())
# 读取
print(response.read().decode("utf-8"))

# 下载网页
# with open("baidu.html","w",encoding="utf-8") as f:
#     f.write(response.read().decode("utf-8"))

# 下载网页 图片 视频
urllib.request.urlretrieve(ulr, filename="baidu.html")